package ie.dkit.java3Demulation.objects3d;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Vector;

import ie.dkit.java3Demulation.transforming.Transformable;
import ie.dkit.java3Demulation.drawer.Line3DDrawable;

public class Rectangle implements Transformable, Line3DDrawable {

	private Point3D leftUpper, leftBottom, rightBottom, rightUpper,
			m_RoationPoint, m_Centre;

	private String m_RectangleName;

	public Rectangle() {
		this(new Point3D(-100, 100, 0), new Point3D(-100, -100, 0),
				new Point3D(100, 100, 0), new Point3D(100, -100, 0));
		m_RectangleName = "Rectangle";
	}

	public Rectangle(Point3D leftUpper, Point3D leftBottom, Point3D rightUpper,
			Point3D rightBottom) {
		this.leftUpper = leftUpper;
		this.leftBottom = leftBottom;
		this.rightBottom = rightBottom;
		this.rightUpper = rightUpper;
		double xc = (leftUpper.getX() + rightBottom.getX()) / 2;
		double yc = (leftUpper.getY() + rightBottom.getY()) / 2;
		double zc = (leftUpper.getZ() + rightBottom.getZ()) / 2;
		Point3D p = new Point3D(xc, yc, zc);
		m_Centre = p;
	}

	public Point3D getCentre() {
		return m_Centre;
	}

	public Point3D getPoint1() {
		return leftUpper;
	}

	public void setLeftUpper(Point3D point3D) {
		this.leftUpper = point3D;
	}

	public Point3D getLeftBottom() {
		return leftBottom;
	}

	public void setLeftBottom(Point3D point3D) {
		this.leftBottom = point3D;
	}

	public Point3D getRightBottom() {
		return rightBottom;
	}

	public void setRightBottom(Point3D point3D) {
		this.rightBottom = point3D;
	}

	public Point3D getM_Point4() {
		return rightUpper;
	}

	public void setM_Point4(Point3D point3D) {
		this.rightUpper = point3D;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ie.dkit.java3Demulation.objects.GraphicsObject#getName()
	 */
	public String getName() {
		return m_RectangleName;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ie.dkit.java3Demulation.objects.GraphicsObject#setName(java.lang.String)
	 */
	public void setName(String name) {
		m_RectangleName = name;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ie.dkit.java3Demulation.transforming.Transformable#getPoints()
	 */
	public Collection<Point3D> getPoints() {
		Collection<Point3D> returnValue = new ArrayList<Point3D>();
		returnValue.add(leftUpper);
		returnValue.add(leftBottom);
		returnValue.add(rightBottom);
		returnValue.add(rightUpper);
		return returnValue;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ie.dkit.java3Demulation.transforming.Transformable#getRotationPoint()
	 */
	public Point3D getRotationPoint() {
		return m_RoationPoint;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ie.dkit.java3Demulation.transforming.Transformable#setRotationPoint(ie.dkit.java3Demulation.objects3d.Point3D)
	 */
	public void setRotationPoint(Point3D point3D) {
		m_RoationPoint = point3D;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ie.dkit.java3Demulation.linedrawing.Drawable#getLines()
	 */
	public Collection<Line3D> getLines() {
		Collection<Line3D> returnValue = new Vector<Line3D>();
		returnValue.add(new Line3D(leftUpper, leftBottom));
		returnValue.add(new Line3D(leftBottom, rightBottom));
		returnValue.add(new Line3D(rightBottom, rightUpper));
		returnValue.add(new Line3D(rightUpper, leftUpper));
		return returnValue;
	}
}
